package cn.edu.cdut.controller;

import cn.edu.cdut.dto.MyRes;
import cn.edu.cdut.model.StudentInfo;
import cn.edu.cdut.service.ComputeScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

/**
 * Author  kobe
 * Created on 2017-06-01-17:16
 */
@RestController
public class ComputeScoreController {

        @Autowired
        private ComputeScoreService computeScoreService;

        //计算成绩
        @GetMapping("/computeScore")
        public MyRes computeScore() {
                try {
                        computeScoreService.computeScore();
                }catch (Exception e) {
                        return new MyRes(201, "计算失败！", null);
                }
                return new MyRes(200, "计算完毕！", null);
        }

        //获得所有成绩
        @GetMapping("/getAllStuScore")
        public MyRes getAllStuScore() {
                return computeScoreService.getAllStuScore();
        }

        //修改成绩
        @PostMapping("/updateScore")
        public MyRes updateScore(@RequestBody StudentInfo studentInfo, BindingResult bindingResult) {
                if (bindingResult.hasErrors()) {
                        return new MyRes(201, "提交失败！", null);
                }
                return computeScoreService.updateScore(studentInfo);
        }

        //获得单个成绩
        @GetMapping("/getStuScore")
        public MyRes getStuScore(@RequestParam("stuId") String stuId) {
                return computeScoreService.getStuScore(stuId);
        }
}





